package com.da.javatest.leetCode;

/**
 * @author chenlida
 * @date 2019/1/5 13:59
 * @description
 */
public class Code496 {
    public int[] nextGreaterElement(int[] nums1, int[] nums2) {
        for (int i = 0; i < nums1.length; i++) {
            int target = nums1[i];
            for (int j = 0; j < nums2.length; j++) {
                if (nums2[j] == target) {
                    if (j == nums2.length - 1) {
                        nums1[i] = -1;
                    } else {
                        int max = getMax(nums2, j);
                        nums1[i] = nums1[i] > max ? -1 : max;
                    }
                    break;
                }
            }
        }
        return nums1;
    }

    private int getMax(int[] nums, int start) {
        int temp = nums[start];
        int result = -1;
        for (int i = start + 1; i < nums.length; i++) {
            if (temp < nums[i]) {
                return nums[i];
            }
        }
        return result;
    }
}
